import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Callable;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 徐海涛
 * Date: 2022-01-12
 * Time: 14:09
 */
class Card {
    private int rank;//数字
    private String suit;//花色

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public String toString() {
        return "["+this.suit+"："+this.rank+" ]";
    }
}

//没有大小王：1 2 3 ..... 10 11 12 13
public class TestDemo2 {
    
    //定义4个花色
    private static final String[] suits = {"♥","♠","♣","♦"};

    //买52张牌
    public static List<Card> buyCard(){
        ArrayList<Card> cards = new ArrayList<>();
        for (int i = 0; i < 4; i++) {//4种花色
            for (int j = 0; j <= 13; j++) {//没种花色13张牌
                String suit = suits[i];
                int rank = j;
                Card card = new Card(rank,suit);//完成一张牌
                cards.add(card);
                //for循环下面可以直接这样写
                //card.add(new Card(j,suits[i]));
            }
        }
        return cards;
    }

    private static void swap(List<Card> cards,int i,int j) {//交换洗牌
        Card tmp = cards.get(i);//先用tmp暂时存放i下标
        cards.set(i, cards.get(j));//将i下标换成j下标
        cards.set(j,tmp);//将j下标换成tmp

    }

    public static void shuffle(List<Card> cards) {//洗牌
        int size = cards.size();
        for (int i = size-1; i >0 ; i--) {//size-1,52张牌下标为52-1
            Random random = new Random();//生成一个随机数
            int rand = random.nextInt(i);//生成一个随机数
            swap(cards,i,rand);
        }
    }
    
    public static void main1(String[] args) {
        List<Card> cards = buyCard();
        System.out.println("买牌：" +cards);
        shuffle(cards);
        System.out.println("洗牌: " + cards);
        System.out.println("揭牌：3个人每个人轮流揭5张牌");

        ArrayList<List<Card>> hand = new ArrayList<>();
        //二维数组
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        //每个人轮流揭牌
        //揭一张少一张，每次都时揭的0下标的牌
        for (int i = 0; i < 5; i++) {//5张牌
            for (int j = 0; j < 3; j++) {//3个人
                Card card = cards.remove(0);//每揭1次牌，就删除0下标
                //删除的0下标为揭开的牌
                //揭开拿到的牌以后放在的位置
                hand.get(j).add(card);
            }
        }
        System.out.println("第1个人的牌: " + hand1);
        System.out.println("第2个人的牌: " + hand2);
        System.out.println("第3个人的牌: " + hand3);
        System.out.println("剩下的牌: "+cards);
    }

    //杨辉三角
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        //第一行
        list.add(1);
        ret.add(list);//完成第一行
        for (int i = 1; i <numRows ; i++) {
            List<Integer> list1 = new ArrayList<>();
            list1.add(1);//第一行为1
            List<Integer> preRow = ret.get(i-1);//上一行
            for (int j = 1; j < i; j++) {//j和i相等时，为最后一个数
                int num1 = preRow.get(j) + preRow.get(j-1);
                list1.add(num1);
            }
            list1.add(1);//最后一个数为1
            ret.add(list1);
        }
        return ret;
    }
    






    public static void main(String[] args) {

    }
}
